package com.nuoyuan.wx.task;

import com.nuoyuan.wx.dao.po.ProductPo;
import com.nuoyuan.wx.service.ProductService;
import com.nuoyuan.wx.vo.ProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @Package com.nuoyuan.wx
 * @ClassName ProductExpireTask
 * @Description TODO
 * @Author linus
 * @Date 2020-02-22 14:10
 * @Version 1.0
 **/
//@Component
public class ProductExpireTask {
    @Autowired
    private ProductService productService;

   // @Scheduled(cron="*/6 * * * * ?")
    private void execute(){
        List<ProductPo> expireProducts = productService.getExpires();
        if(CollectionUtils.isEmpty(expireProducts)) {
            return;
        }

        for(ProductPo p : expireProducts) {
            ProductVo vo = new ProductVo();
            vo.setProductId(p.getProductId());
            vo.setIfEnd(true);
            productService.update(vo);
        }

    }
}
